<template>
  <div>
    <OperateC :add="addSysTestUser" :edit="editSysTestUser" :remove="removeSysTestUser"></OperateC>
    <SysTestUserTable></SysTestUserTable>
    <SysTestUserDialog></SysTestUserDialog>
  </div>
</template>

<script>
  import SysTestUserDialog from "@/components/dialog/SysTestUserDialog";
  import OperateC from "@/components/OperateC";
  import SysTestUserTable from "@/components/table/SysTestUserTable";
  import {deleteSysTestUserByIds, getSysTestUsers} from "@/api/sysTestUser";
  export default {
    name: "SysTestUserView",
    components: {SysTestUserDialog, OperateC, SysTestUserTable},
    data() {
      return {

      }
    },
    methods: {
      addSysTestUser() {
        let params = {
          dialogFormVisible: true,
          dialogTitle: "添加测试用户"
        }
        this.$store.commit("sysTestUser/openDialogForm", params);
      },
      editSysTestUser() {
        let selected = this.$store.state.sysTestUser.multipleSelection;
        if (selected.length < 1) {
          this.$message.warning("你还没有选中数据哦！");
          return;
        }
        if (selected.length > 1) {
          this.$message.warning("一次只能修改一条数据哦！")
          return;
        }
        this.$store.dispatch("sysTestUser/editSysTestUser", selected[0]);
      },
      removeSysTestUser() {
        let selected = this.$store.state.sysTestUser.multipleSelection;
        if (selected.length < 1) {
          this.$message.warning("请先选择要删除的数据哦！");
          return;
        }
        this.$confirm('确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteSysTestUserByIds(selected).then((res) => {
            this.$message.success(res.data.msg);
            // 刷新
            let params = {
              "current": this.$store.state.sysTestUser.currentPage,
              "size": this.$store.state.sysTestUser.pageSize
            };
            getSysTestUsers(params).then((res) => {
              this.$store.state.sysTestUser.tableData = res.data.data;
              this.$store.state.sysTestUser.total = res.data.total;
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
    }
  }
</script>

<style scoped>

</style>